/**
 * uniapp的request
 */
function request(url, data = {}, method = "GET") {
	return new Promise(function(resolve, reject) {
		uni.request({
			url: url,
			data: data,
			header: {
				'Content-Type': 'application/x-www-form-urlencoded'
			},
			method: method,
			success: (res) => {
				if (res.statusCode == 200) {
					//请求正常200
					resolve(res.data);
				} else {
					//请求失败
					reject("请求失败")
				}
			},
			fail: function(err) {
				reject("请求失败")
			}
		});
	})
}
/**
 * GET请求封装
 */
function get(url, data = {}) {
  return request(url, data, 'GET')
}

/**
 * POST请求封装
 */
function post(url, data = {}) {
  return request(url, data, 'POST')
}
module.exports = {
	request,
	get,
	post
}
